import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class MusicFileUtils {

	public static Melody readFile(String filePath) {
		FileInputStream fis;
		ObjectInputStream ois = null;
		Melody melody = null;
		try {
			fis = new FileInputStream(filePath);
			ois = new ObjectInputStream(fis);
			melody = (Melody) ois.readObject();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			try {
				if (ois != null) {
					ois.close();
				}
			} catch (IOException e) {
			}
		}
		
		return melody;
	}

	public static void writeFile(Melody melody, String filePath) {
		ObjectOutputStream oos = null;
		try {
			FileOutputStream fos = new FileOutputStream(filePath);
			
			oos = new ObjectOutputStream(fos);
			
			oos.writeObject(melody);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (oos != null) {
					oos.close();
				}
			} catch (IOException e) {
			}
		}
	}
}
